﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SilverlightSdms.AdminService;

namespace SilverlightSdms
{
    public partial class Home : Page
    {
        public Home()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            var client = new UsersServiceClient();

            client.GetUsersWithRolesCompleted += (s, ea) =>
                {
                    //dataGrid1.AutoGenerateColumns = true;
                    dataGridUsers.ItemsSource = ea.Result;
                };
            client.GetUsersWithRolesAsync();
        }

        private void btnAddUser_Click(object sender, RoutedEventArgs e)
        {
            var client = new UsersServiceClient();

            client.AddUserCompleted += (s, ea) =>
            {
                this.button1_Click(this, new RoutedEventArgs());
                
            };
            //Services.LightUser user = new Services.LightUser();
            //user.Password = txtBoxPassword.Text;
            //user.UserName = txtboxUserName.Text;
            //client.AddUserAsync(user);
        }

        private void dataGridUsers_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            dataGridUserRoles.AutoGenerateColumns = true;
            dataGridUserRoles.ItemsSource = (dataGridUsers.SelectedItem as LightUser).Roles;
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            var client = new UsersServiceClient();

            client.GetUsersCompleted += (s, ea) =>
                {
                    dataGridAllUsers.AutoGenerateColumns = true;
                    dataGridAllUsers.ItemsSource = ea.Result;
                };
            
            client.GetUsersAsync();
        }
    }
}